from game import *

class Camera(pygame.Rect):

	def __init__(self, game, rect, tracker):
		pygame.Rect.__init__(self, rect)
		self.game = game
		self.tracker = tracker
		
		self.pos = self.tracker.pos
		self.vel = Vector()

		
	def update(self):
	
		dist = self.tracker.pos - self.pos
		self.vel = dist
		self.vel *= .05
		
		if (self.left < 0 and self.tracker.pos.x < self.pos.x) or (self.right > self.game.world.right and self.tracker.pos.x > self.pos.x):
			self.vel.x = 0
			
		if (self.top < 0 and self.tracker.pos.y < self.pos.y) or (self.bottom > self.game.world.bottom and self.tracker.pos.y > self.pos.y):
			self.vel.y = 0
		
		self.pos += self.vel
		self.center = self.pos.to_list()

		self.game.console.log("vel: " + str(self.vel))
		self.game.console.log("pos: " + str(self.pos))
		self.game.console.log("center: " + str(self.center))
		
	def translate(self, pos = Vector()):
		return pos - Vector.list(self.topleft)


